package core
{
import flash.display.Stage;
import flash.display.StageDisplayState;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.FullScreenEvent;


public class StageProxy
{
	private static var _stage:Stage;

	public static function get stage():Stage
	{
		return _stage;
	}

	public static function set stage(value:Stage):void
	{
		_stage = value;
        lastWidth = _normalStageWidth = value.stageWidth;
        lastHeight = _normalStageHeight = value.stageHeight;
		stage.addEventListener(FullScreenEvent.FULL_SCREEN, screenModeChange);
        stage.addEventListener(Event.RESIZE, onStageResize);
		
		stage.scaleMode = StageScaleMode.NO_SCALE;
	}
    
    private static var lastWidth:Number = 0;
    private static var lastHeight:Number = 0;
	
	private static var _normalStageWidth:Number;

	public static function get normalStageWidth():Number
	{
		return _normalStageWidth;
	}
	
	private static var _normalStageHeight:Number;
	
	public static function get normalStageHeight():Number
	{
		return _normalStageHeight;
	}
	
	public static function get screenWidth():Number
	{
		return _stage.stageWidth;
	}
	
	public static function get screenHeight():Number
	{
		return _stage.stageHeight;
	}
	
	private static var _screenMode:String = StageDisplayState.NORMAL;

	public static function get screenMode():String
	{
		return _screenMode;
	}
	
	public static function get isFullScreenMode():Boolean
	{
		return _screenMode == StageDisplayState.FULL_SCREEN;
	}
	
	public static function changeScreenMode(mode:String = null):void
	{
        if (mode == screenMode) return;
        if (!mode)
        {
            mode = screenMode == StageDisplayState.FULL_SCREEN ? StageDisplayState.NORMAL : StageDisplayState.FULL_SCREEN;
        }
        stage.displayState = mode;
	}
    
    private static function showFullScreen():void
    {		
        _screenMode = StageDisplayState.FULL_SCREEN;
    }
    
    private static function showNormalScreen():void
    {
        _screenMode = StageDisplayState.NORMAL;
    }
	
	
	
	private static function screenModeChange(event:FullScreenEvent):void
	{
		if (event.fullScreen)
		{
			showFullScreen();
		}
		else
		{
			showNormalScreen();
		}
	}
	
    public static function lock():void
    {
        Game.instance.container.mouseChildren = false;
    }
    
    public static function unlock():void
    {
        Game.instance.container.mouseChildren = true;
    }
}
}





